

package com.hazelcast.jet.impl.operation;

import com.hazelcast.jet.impl.execution.init.JetInitDataSerializerHook;
import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;
import com.hazelcast.nio.serialization.impl.Versioned;
import com.hazelcast.spi.impl.eventservice.impl.Registration;

import java.io.IOException;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;

public class AddJobStatusListenerOperation extends AsyncJobOperation implements Versioned {
    private boolean isLightJob;
    private Registration registration;

    public AddJobStatusListenerOperation() {
    }

    public AddJobStatusListenerOperation(long jobId, boolean isLightJob, Registration registration) {
        super(jobId);
        this.isLightJob = isLightJob;
        this.registration = registration;
    }

    @Override
    public CompletableFuture<UUID> doRun() {
        return getJobCoordinationService().addJobStatusListener(jobId(), isLightJob, registration);
    }

    @Override
    public int getClassId() {
        return JetInitDataSerializerHook.ADD_JOB_STATUS_LISTENER_OP;
    }

    @Override
    protected void writeInternal(ObjectDataOutput out) throws IOException {
        super.writeInternal(out);
        out.writeBoolean(isLightJob);
        registration.writeData(out);
    }

    @Override
    protected void readInternal(ObjectDataInput in) throws IOException {
        super.readInternal(in);
        isLightJob = in.readBoolean();
        registration = new Registration();
        registration.readData(in);
    }
}
